Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for stream3 buffering using cork #6493

Merged
merged 2 commits into from
May 12, 2016
Merged

test: add tests for stream3 buffering using cork #6493

merged 2 commits into from
May 12, 2016

Conversation

alexjeffburke
Copy link
Contributor

@alexjeffburke alexjeffburke commented Apr 30, 2016

Checklist
  • tests and code linting passes
  • a test and/or benchmark is included
  • the commit message follows commit guidelines
Description of change

Add tests of stream3 the buffering behaviour of cork() followed by uncork()/end(). Opening a PR for review per request of the streams-wg.

cc @nodejs/readable-stream

@nodejs-github-bot nodejs-github-bot added the test Issues and PRs related to the tests. label Apr 30, 2016
@alexjeffburke alexjeffburke changed the title Cork tests test: add tests for stream3 buffering using cork Apr 30, 2016
@mscdex mscdex added the stream Issues and PRs related to the stream subsystem. label Apr 30, 2016
@calvinmetcalf
Copy link
Contributor

@nodejs/streams

@mcollina
Copy link
Member

mcollina commented May 1, 2016

Thanks!!! You might want to check this runs on node v4, just in case.

I think we should start the habit of explaining the tests in plain English first, because otherwise they imply a lot of knowledge around the stream state machine and they might scare newcomers. Most of it is already explained in the comments, it's probably just a matter of putting a paragraph to describe it at the beginning.

Use const instead of var for the non-changing variables. I will also argue that we should stick to use function () {} instead of the fat arrows when we attach methods to prototypes.

How about you add a test also for _writev?

@alexjeffburke
Copy link
Contributor Author

Thanks for the feedback @mcollina - so I've just pushed an update with the following changes:

  • set _write using a full function (having looked kinda like it too)
  • used const for includes and expectedChunks
  • tightened up a couple of the comments

Regarding _writev, it appeared to me test-stream-writev.js does some of that but I don't think its the most approachable code. What I'd be tempted to do in that case is separate out a test for all the different encodings from the buffering behaviour using it.

Finally, happy to add a paragraph but the question would be where and using /* */ or multiple // ? Could you perhaps point me to another file where this is done, keen to follow not set any precedents for now :)

@calvinmetcalf
Copy link
Contributor

What I'd be tempted to do in that case is separate out a test for all the different encodings from the buffering behaviour using it.

that would be amazing

as for comment style I believe they tend to be // but I don't believe there are hard and fast rules

// there was a chunk
assert.ok(seen);

var expected = new Buffer(expectedChunks[i]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buffer.from(expectedChunks[i])

@jasnell
Copy link
Member

jasnell commented May 1, 2016

Left a couple nits pointing where Buffer.from() can be used instead of new Buffer(). That would obviously only apply to master/v6/v5 tho so if this test also needs to run in v4, feel free to ignore!

@alexjeffburke
Copy link
Contributor Author

@jasnell appreciate you taking a look!

I'm happy to do that, but per discussions of @nodejs/streams it may be preferable to allow these to run against all versions of node that implement streams3. What could be worth an explicit decision is if that should be evident within 'in-tree' files or if any necessary glue be added in ports to readable-stream repo.

@jasnell
Copy link
Member

jasnell commented May 1, 2016

Works for me... as I said, feel free to ignore ;-) That's actually the main reason why I didn't go through all of the existing tests and change them to use Buffer.from (or the other ones).

Come to think of it, as a best practice it might be a good idea to explicitly indicate (using code comments) in the tests themselves which node.js versions the test needs to be able to run on.

@Trott
Copy link
Member

Trott commented May 2, 2016

Come to think of it, as a best practice it might be a good idea to explicitly indicate (using code comments) in the tests themselves which node.js versions the test needs to be able to run on.

Yes, please. My dream is to eventually have that information as metadata in test comments so that an automated process can confirm that changes to tests don't suddenly make them pass in versions where they are supposed to fail. But that is way beyond the scope of this PR. :-)

@mcollina
Copy link
Member

mcollina commented May 2, 2016

👍 on writing a comment stating on which node version this belongs to.

@alexjeffburke
Copy link
Contributor Author

I'll look at adding those descriptive paragraphs - as for versioning, any objection to the following:

// node version target: 0.12

@alexjeffburke
Copy link
Contributor Author

Just updated these two tests to address comments:

  • added a couple of lines explaining the test
  • included some info about the node version targeted

I also renamed consumeChunks() -> writeChunks() to better its behaviour.

@mcollina
Copy link
Member

mcollina commented May 9, 2016

Apart for the two Buffer.from nits, LGTM.

CI: https://ci.nodejs.org/job/node-test-pull-request/2543/.

@calvinmetcalf
Copy link
Contributor

fyi I've got a shim working so I can run the readable streams (including the Buffer.from) against old node

@alexjeffburke
Copy link
Contributor Author

alexjeffburke commented May 9, 2016

@mcollina @calvinmetcalf re Buffer.from() - I understand the objection, but that's why I previously asked which version of node in-tree tests should target hence the exchange with @jasnell above :)

It's easy enough to conditionally check for the Buffer method etc, but it's still unclear whether the in-tree tests should target the lowest version of node (thus compat glue be added in test) or if it is ok for this to be handled in the readable-streams repo.

@jasnell
Copy link
Member

jasnell commented May 9, 2016

Given the requirement that readable-stream has to support older versions of Node I think not going with the Buffer.from() here is appropriate.

@calvinmetcalf
Copy link
Contributor

sorry, to clarify this is handled in readable-stream already

@alexjeffburke
Copy link
Contributor Author

Seems like I can leave the files as is with 'new Buffer()'. Given previous LGTMs, is there anything else I should do before these can be landed?

@jasnell
Copy link
Member

jasnell commented May 11, 2016

LGTM if @nodejs/streams is good with it.

@calvinmetcalf calvinmetcalf merged commit 9d0b7d8 into nodejs:master May 12, 2016
@calvinmetcalf
Copy link
Contributor

calvinmetcalf commented May 12, 2016

yup it's good, merged

@alexjeffburke
Copy link
Contributor Author

Awesome, thanks! Very glad this was useful.

evanlucas pushed a commit that referenced this pull request May 17, 2016
adds 2 new tests for streams3 cork behavior, cork then uncork and cork then end

PR-URL: #6493

Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins
Copy link
Contributor

@nodejs/streams should this be backported to v4?

@mcollina
Copy link
Member

mcollina commented Jun 3, 2016

@thealphanerd Ideally yes, if it is not passing ping us.

MylesBorins pushed a commit that referenced this pull request Jul 11, 2016
adds 2 new tests for streams3 cork behavior, cork then uncork and cork then end

PR-URL: #6493

Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jul 11, 2016
adds 2 new tests for streams3 cork behavior, cork then uncork and cork then end

PR-URL: #6493

Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jul 12, 2016
adds 2 new tests for streams3 cork behavior, cork then uncork and cork then end

PR-URL: #6493

Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jul 12, 2016
adds 2 new tests for streams3 cork behavior, cork then uncork and cork then end

PR-URL: #6493

Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Jul 12, 2016
MylesBorins pushed a commit that referenced this pull request Jul 14, 2016
adds 2 new tests for streams3 cork behavior, cork then uncork and cork then end

PR-URL: #6493

Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jul 14, 2016
adds 2 new tests for streams3 cork behavior, cork then uncork and cork then end

PR-URL: #6493

Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stream Issues and PRs related to the stream subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants